package com.mingjie.daydayup;

import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;

import receiver.SmsBroadcastReceiver;

public class SmsTestActivity extends AppCompatActivity {
    private EditText editText;
    private SmsBroadcastReceiver smsReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sms_test);
        editText = (EditText) findViewById(R.id.editText);
    }

    @Override
    protected void onStart() {
        super.onStart();
        smsReceiver = new SmsBroadcastReceiver();
        IntentFilter intentFilter = new IntentFilter(SmsBroadcastReceiver.SMS_RECEIVED_ACTION);
        intentFilter.setPriority(Integer.MAX_VALUE);
        this.registerReceiver(smsReceiver, intentFilter);
        smsReceiver.setOnReceiveSmsListener(new SmsBroadcastReceiver.OnReceiveSmsListener() {
            @Override
            public void OnReceive(String content) {
                editText.setText(content);
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        this.unregisterReceiver(smsReceiver);
    }
}
